home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-03-19 | 16.7 KB | 542 lines | [TEXT/MPS ] |
- #
- # ****************************************************************************
- #
- # File Name: Gestalt.Lib
- #
- # Contains: xxx put contents here xxx
- #
- # Written by: KTA, KL, ML, GS et al
- #
- # Copyright: © 1993-1995 by Apple Computer, Inc., all rights reserved.
- #
- # ****************************************************************************
- # C h a n g e H i s t o r y (most recent first):
- # ****************************************************************************
- #
- # Vers Date Author Description
- # ---- -------- ------ ---------------------------------------------
- # 1.0.110> 11/8/95 ML GestaltOProcessorType - use 'cput' instead of 'proc'
- # 1.0.19+> 11/8/95 ML GestaltOProcessorType - use 'cput' instead of 'proc'
- # <1.0.19> 4/11/95 KTA Moved IsPowerPC() to TargetCheck.Lib
- # <1.0.18> 3/8/95 ML GestaltMachineType() - revise header documentation
- # <1.0.17> 11/30/94 ML Added Exception Handling
- # <1.0.16> 9/26/94 ML return LowWordOfAnswer() back to original form, create
- # task GetGestaltValue(), replace instances of
- # LowWordOfAnswer() with GetGestaltValue().
- # <1.0.15> 9/21/94 ML removed gestres, revise gestalt calls for VU 2.1
- # <1.0.14> 3/23/94 KTA Added marks.
- # <1.0.13> 3/15/94 ML Moved all calls that were non-Gestalt to TargetCheck.lib.
- # Removed dependencies on other libs, add support for multiple
- # monitor bit depth.
- # <1.0.12> 12/8/93 KTA FormLongNumber() - Removed quitting the MathTool - if multiple
- # targets are running the tool will not be available.
- # <1.0.9> 12/3/93 KTA MachineState now returns logical and physical memory in bytes,
- # added FormLongNumber() task.
- # <1.0.8> 12/2/93 KTA Removed globals isOff, IsOn, VirtualMemory, notAvail, etc.
- # <1.0.7> 12/2/93 KTA Added tasks GestaltSystemArchitecture() and IsPowerPC(). Added
- # SystemArchitecture as MachineState() target descriptor.
- # <1.0.6> 11/30/93 ML Added ReturnMachineName parameter to GestaltMachineType, now
- # returns Machine umber by default
- # <1.0.5> 8/9/93 KTA MachineState() - Updates for new Pheonix data format .
- # <1.0.4> 7/19/93 KTA InitOnTarget had a syntax error that wasn't caught.
- # <1.0.3> 7/15/93 KTA Changed the name of some tasks so they wouldn't conflict with
- # Gestalt.vulib, changed error checking in InitOnTarget(), removed
- # SystemVersion() and MachineName().
- # <1.0.2> 6/8/93 NAGA unmark tasks that are not published
- # <1.0.1> 5/21/93 NAGA Adding header and porting old files to follow new standards
- #
- # ****************************************************************************
- #
-
- ########################################################################
- # External libraries
- #=======================================================================
- Libraries "ExceptionHandling.lib";
- ##################################################################################
- # Check32Bit()
- #=======================================================================
- # Author: GS
- # Description: This routine will check the state of 32 bit addressing,
- # and returns the value.
- # Parameters: None
- # Returns: Values
- # On := 1
- # Off := 0
- # not Avail := -1
- # GestaltError
- # in the first item a value described above. The second item is a text
- # string description of the value.
- #=======================================================================
- # History:
- # ML 11/30/94 Added support for exception handling
- ##################################################################################
- Task Check32Bit()
- begin
- theResult := GetGestaltValue(_gestalt( 'addr' ));
-
- if (theResult & (1 << 0))
- retVal := {1, "32 bit addressing is ON"};
-
- else if (theResult & (1 << 2))
- retVal := {0, "32 bit addressing is available but turned OFF"};
-
- else if not ((theResult & (1 << 0)) or (theResult & (1 << 1)) or (theResult & (1 << 2)))
- retVal := {-1, "32 bit addressing is not available on this machine"};
-
- # if (gestRes[1])
- # retVal := {gestRes[1], "Gestalt Error (-5550 is gestalt unavailable error)"};
-
- return retVal;
- end;
-
-
-
- ##################################################################################
- # CheckVM()
- #=======================================================================
- # Author: GS
- # Description: Checks to see if VM is turned on.
- #
- # Parameters: None
- # Returns: On := 1
- # Off := 0
- # not Avail := -1
- # GestaltError
- # if VM is on gestalt('vm ') returns a 1
- # any other case (not available, not turned on is a 0)
- #=======================================================================
- # History:
- # KTA 12/02/93 Removed isOff, IsOn, VirtualMemory, notAvail, etc.
- # ML 11/30/94 Added support for exception handling
- ##################################################################################
- TASK CheckVM()
- begin
- vmValue := GetGestaltValue(_gestalt( 'vm ' ));
-
- if (vmValue = 0)
- begin
- theMMU := GetGestaltValue(_gestalt( 'mmu ' ));
- if(theMMU > 1)
- retVal := {0, "VM is available and OFF"};
- else
- retVal := {-1, "VM is NOT available on this machine"};
- end;
-
- else if (vmValue & (1 << 0))
- retVal := {1, "VM is ON"};
-
- # errorCode := gestRes[1];
- # if (errorCode)
- # retVal := {errorCode, "Gestalt Error (-5550 is gestalt unavailable error)"};
-
- return retVal;
- end;
-
- ##################################################################################
- # LowWordOfAnswer()
- #=======================================================================
- # Author: GS
- # Description: Returns second item of a list.
- #
- # Parameters: None
- # Returns: second item of a list
- #=======================================================================
- # History:
- #
- ##################################################################################
- task LowWordOfAnswer(Answer)
- begin
-
- tempVal := Answer[2];
- retVal := tempVal[2];
-
- return retVal;
- end;
-
- ##################################################################################
- # GetGestaltValue()
- #=======================================================================
- # Author: GS
- # Description: Checks a 2 element list, If 2nd element type list,
- # call LowWordOfAnswer, otherwise return the element.
- #
- # Parameters: pAnswer - 2 element list returned from VU's built-in
- # gestalt task
- # Returns: integer
- #=======================================================================
- # History:
- # ML 9/26/94 created
- ##################################################################################
- task GetGestaltValue(pAnswer)
- begin
-
- tempVal := pAnswer[2];
- if (typeof(tempVal) = 'list')
- retVal := LowWordOfAnswer(pAnswer);
- else
- retVal := tempVal;
- return retVal;
- end;
-
-
- ##################################################################################
- # GestaltLongError()
- #=======================================================================
- # Author: GS
- # Description: Will return a longer error response in the form of a string.
- #
- # Parameters: None
- # Returns: String with error text
- #=======================================================================
- # History:
- #
- ##################################################################################
- task GestaltLongError(gestaltAnswer := {0,{0,0}})
- begin
- kGestaltNoErr := 0;
- kGestaltUnknownErr := -5550;
- kGestaltUndefSelectorErr := -5551;
-
- gesErr := gestaltAnswer[1];
- if gesErr = kGestaltNoErr
- return "No error";
- else if gesErr = kGestaltUnknownErr
- return "Error: Could not obtain response";
- else if gesErr = kGestaltUndefSelectorErr
- return "Error: Undefined selector";
- else
- return "Error: Unknown error code: {gesErr}";
- end;
-
-
-
-
-
- ##################################################################################
- # GestaltFPUType()
- #=======================================================================
- # Author: Derived from Virtual User 2.0 Example libraries
- # Description: Returns FPU type.
- #
- # Parameters: None
- # Returns: NoFPU
- # 68881
- # 68882
- # 68040
- # unknFPU
- #=======================================================================
- # History:
- # ML 9/20/94 Funnel gestalt answer through GetGestaltValue task
- # (VU 2.1 support)
- # ML 11/30/94 Added support for exception handling
- ##################################################################################
- TASK GestaltFPUType()
- begin
- gesAns := _Gestalt('fpu ');
- gesErr := gesAns[1];
- if (not gesErr)
- begin
- fpuAns := GetGestaltValue(gesAns);
- if fpuAns = 0
- return "NoFPU";
- else if fpuAns = 1
- return "68881";
- else if fpuAns = 2
- return "68882";
- else if fpuAns = 3
- return "68040FPU";
- else
- return "unknFPU";
- end;
- else
- return GestaltLongError(gesAns);
- end;
-
-
-
- ##################################################################################
- # GestaltMachineType()
- #=======================================================================
- # Author: Derived from Virtual User 2.0 Example libraries
- # Description: Checks machine being tested and returns string with Machine Type.
- #
- # Parameters: 0 - return machine number
- # 1 - return machine name
- # Returns: String with Machine Name or integer with machine number
- # (See list below)
- #=======================================================================
- # History:
- # ML 11/30/93 Added ReturnMachineName parameter, now returns Machine
- # number by default
- # ML 9/20/94 Funnel gestalt answer through GetGestaltValue task
- # (VU 2.1 support)
- # ML 11/30/94 Added support for exception handling
- ##################################################################################
- TASK GestaltMachineType(ReturnMachineName := 0)
- begin
- gesAns := _Gestalt('mach');
- gesErr := gesAns[1];
- if (not gesErr)
- begin
- machAns := GetGestaltValue(gesAns);
- if (ReturnMachineName)
- begin
- if machAns = 1
- return "Classic";
- else if machAns = 2
- return "MacXL";
- else if machAns = 3
- return "Mac512KE";
- else if machAns = 4
- return "MacPlus";
- else if machAns = 5
- return "MacSE";
- else if machAns = 6
- return "MacII";
- else if machAns = 7
- return "MacIIx";
- else if machAns = 8
- return "MacIIcx";
- else if machAns = 9
- return "MacSE030";
- else if machAns = 10
- return "Portable";
- else if machAns = 11
- return "MacIIci";
- else if machAns = 13
- return "MacIIfx";
- else if machAns = 17
- return "MacClassic";
- else if machAns = 18
- return "MacIIsi";
- else if machAns = 19
- return "MacLC";
- else if machAns = 20
- return "Quadra900";
- else if machAns = 21
- return "Powerbook170";
- else if machAns = 22
- return "Quadra700";
- else if machAns = 23
- return "ClassicII";
- else if machAns = 24
- return "PowerBook100";
- else if machAns = 25
- return "PowerBook140";
- else if machAns = 26
- return "Quadra 950";
- else
- return MachAns;
- end; # if ReturnMachineName
- else
- return MachAns;
- end; # if (not gesErr)
- else
- return GestaltLongError(gesAns);
- end;
-
-
- ##################################################################################
- # GestaltProcessorType()
- #=======================================================================
- # Author: Derived from Virtual User 2.0 Example libraries
- # Description: Returns the processor running on the test machine
- #
- # Parameters: None
- # Returns: 68000
- # 68010
- # 68020
- # 68030
- # 68040
- #=======================================================================
- # History:
- # ML 9/20/94 Funnel gestalt answer through GetGestaltValue task
- # (VU 2.1 support)
- # ML 11/30/94 Added support for exception handling
- # ML 11/08/95 use 'cput' instead of 'proc'
- ##################################################################################
- TASK GestaltProcessorType()
- begin
- gesAns := _Gestalt('cput');
- gesErr := gesAns[1];
- if (not gesErr)
- begin
- procAns := gesAns[2];
- if procAns = 0
- return "68000";
- else if procAns = 1
- return "68010";
- else if procAns = 2
- return "68020";
- else if procAns = 3
- return "68030";
- else if procAns = 4
- return "68040";
- else if procAns = 257
- return "601";
- else if procAns = 259 # unable to fully test - no PowerSurge machines available
- return "603";
- else
- return "unknProc";
- end;
- else
- return GestaltLongError(gesAns);
- end;
-
-
-
- ##################################################################################
- # GestaltMMUType()
- #=======================================================================
- # Author: Derived from Virtual User 2.0 Example libraries
- # Description: Will return the memory management unit type found operating on the target.
- #
- #
- # Parameters: None
- # Returns: NoMMU
- # AMU
- # 68851
- # 68030MMU
- # 68040MMU
- # unknMMUType
- #=======================================================================
- # History:
- # ML 9/20/94 Funnel gestalt answer through GetGestaltValue task
- # (VU 2.1 support)
- # ML 11/30/94 Added support for exception handling
- ##################################################################################
- TASK GestaltMMUType()
- begin
- gesAns := _Gestalt('mmu ');
- gesErr := gesAns[1];
- if (not gesErr)
- begin
- mmuAns := GetGestaltValue(gesAns);
- if mmuAns = 0
- return "NoMMU";
- else if mmuAns = 1
- return "AMU";
- else if mmuAns = 2
- return "68851";
- else if mmuAns = 3
- return "68030MMU";
- else if mmuAns = 4
- return "68040MMU";
- else
- return "unknMMUType";
- end;
- else
- return GestaltLongError(gesAns);
- end;
-
-
- ##################################################################################
- # GestaltLogicalRAMSize()
- #=======================================================================
- # Author: Derived from Virtual User 2.0 Example libraries
- # Description: Will return the amount of logical RAM located in a machine.
- # (VM+RM)
- #
- #
- # Parameters: None
- # Returns: an integer in megabytes.
- #=======================================================================
- # History:
- # ML 9/20/94 Add VU 2.1 support
- # ML 11/30/94 Added support for exception handling
- ##################################################################################
- TASK GestaltLogicalRAMSize()
- begin
- gesAns := _Gestalt('lram');
- gesErr := gesAns[1];
- if (not gesErr)
- begin
- if (typeof(gesAns[2]) = 'list') # VU 2.0x
- begin
- theHiWord := gesAns[2][1];
- # Gestalt apparently has a problem reporting the full 8MB of physical memory
- # on machines with no virtual memory enabled. This will compensate.
- return (theHiWord + 1) / 16;
- end; # if (typeof(gesAns[2]) = 'list')
- else # VU 2.1x
- return (gesAns[2]);
- end;
- else
- return GestaltLongError(gesAns);
- end;
-
-
- ##################################################################################
- # GestaltPhysicalRAMSize()
- #=======================================================================
- # Author: Derived from Virtual User 2.0 Example libraries
- # Description: Will return the amount of physical RAM located in a machine.
- #
- #
- # Parameters: None
- # Returns: an integer in megabytes.
- #=======================================================================
- # History:
- # ML 9/20/94 Add VU 2.1 support
- # ML 11/30/94 Added support for exception handling
- ##################################################################################
- TASK GestaltPhysicalRAMSize()
- begin
- gesAns := _Gestalt('ram ');
- gesErr := gesAns[1];
- if (not gesErr)
- begin
- if (typeof(gesAns[2]) = 'list') # VU 2.0x
- begin
- theHiWord := gesAns[2][1];
- # Gestalt apparently has a problem reporting the full 8MB of physical memory
- # on machines with no virtual memory enabled. This will compensate.
- return (theHiWord + 1) / 16;
- end; # if (typeof(gesAns[2]) = 'list')
- else # VU 2.1x
- return (gesAns[2]);
- end;
- else
- return GestaltLongError(gesAns);
- end;
-
-
- #########################################################################
- # GestaltSystemArchitecture()
- #=======================================================================
- # Author: KTA
- # Description: Makes a Gestalt call with selector of 'sysa' to determine if the
- # target system is 68K or PowerPC
- # Parameters: none
- # Returns: 0 - Selector not installed (older 68k)
- # 1 - Selector installed - target is 68k based not PowerPC
- # 2 - Selector installed - target is PowerPC based not 68k
- #=======================================================================
- # History:
- # KTA 12/01/93 Created
- # ML 9/20/94 Add VU 2.1 support
- # ML 11/30/94 Added support for exception handling
- ########################################################################
- TASK GestaltSystemArchitecture()
- begin
- gesAns := _Gestalt('sysa');
- #println gesAns;
- if(GesAns[1] = -5551) # Selector not installed (older 68k machine)
- ReturnVal := 0;
- else if (GesAns[1] = 0)
- begin
- SysArchAns := GetGestaltValue(gesAns);
- if( SysArchAns = 1) # 68k system
- returnVal := 1;
- else if ( SysArchAns = 2) # PowerPC native system
- returnVal := 2;
- else
- println "returnVal unknown - {SysArchAns}";
- end;
- else
- println " - a unexpected gestalt error occured - {gesAns}";
-
- return(ReturnVal);
- end;
-
-